import os
import re
import glob

# 定义脚本路径映射
script_path_mapping = {
    "res://scripts/player.gd": "res://scripts/player/player.gd",
    "res://scripts/player_stats.gd": "res://scripts/player/player_stats.gd",
    "res://scripts/player_stats_ui.gd": "res://scripts/ui/player_stats_ui.gd",
    "res://scripts/player_health_bar.gd": "res://scripts/ui/player_health_bar.gd",
    "res://scripts/monster_health_bar.gd": "res://scripts/ui/monster_health_bar.gd",
    "res://scripts/main_menu.gd": "res://scripts/ui/main_menu.gd",
    "res://scripts/skill_tree_ui.gd": "res://scripts/ui/skill_tree_ui.gd",
    "res://scripts/enemy_base.gd": "res://scripts/enemies/enemy_base.gd",
    "res://scripts/sword_master.gd": "res://scripts/enemies/boss/sword_master.gd",
    "res://scripts/enemy_spawner.gd": "res://scripts/enemies/enemy_spawner.gd",
    "res://scripts/dialog_box.gd": "res://scripts/dialog/dialog_box.gd",
    "res://scripts/dialog_manager.gd": "res://scripts/dialog/dialog_manager.gd",
    "res://scripts/bubble_dialog.gd": "res://scripts/dialog/bubble_dialog.gd",
    "res://scripts/npc.gd": "res://scripts/dialog/npc.gd",
    "res://scripts/inventory.gd": "res://scripts/inventory/inventory.gd",
    "res://scripts/inventory_manager.gd": "res://scripts/inventory/inventory_manager.gd",
    "res://scripts/inventory_slot.gd": "res://scripts/inventory/inventory_slot.gd",
    "res://scripts/inventory_slot_ui.gd": "res://scripts/inventory/inventory_slot_ui.gd",
    "res://scripts/inventory_ui.gd": "res://scripts/inventory/inventory_ui.gd",
    "res://scripts/item.gd": "res://scripts/inventory/item.gd",
    "res://scripts/item_data.gd": "res://scripts/inventory/item_data.gd",
    "res://scripts/item_database.gd": "res://scripts/inventory/item_database.gd",
    "res://scripts/item_database_resource.gd": "res://scripts/inventory/item_database_resource.gd",
    "res://scripts/skill_tree.gd": "res://scripts/skills/skill_tree.gd",
    "res://scripts/sword_wave.gd": "res://scripts/skills/sword_wave.gd",
    "res://scripts/gamedata/skill/skill_database.gd": "res://scripts/skills/database/skill_database.gd",
    "res://scripts/level_up_effect.gd": "res://scripts/effects/level_up_effect.gd",
    "res://scripts/main.gd": "res://scripts/core/main.gd",
    "res://scripts/empty_state_machine.gd": "res://scripts/core/empty_state_machine.gd",
    "res://scripts/language_manager.gd": "res://scripts/core/language_manager.gd",
    "res://enemy_base.gd": "res://scripts/enemies/enemy_base.gd"
}

# 获取所有场景文件和资源文件
all_files = []
for ext in ['*.tscn', '*.tres', '*.import', '*.godot']:
    all_files.extend(glob.glob(f"**/{ext}", recursive=True))

# 遍历每个文件
for file_path in all_files:
    print(f"检查文件: {file_path}")
    
    try:
        # 读取文件内容
        with open(file_path, 'r', encoding='utf-8') as f:
            content = f.read()
        
        # 检查是否包含旧路径
        for old_path in script_path_mapping.keys():
            if old_path in content:
                print(f"  - 发现旧路径: {old_path} 在文件 {file_path}")
                
    except UnicodeDecodeError:
        print(f"  - 无法以UTF-8解码文件: {file_path}")
    except Exception as e:
        print(f"  - 处理文件时出错: {file_path}, 错误: {str(e)}")

print("所有文件检查完成！")

# 检查.godot项目文件中的引用
if os.path.exists("project.godot"):
    print("检查project.godot文件...")
    try:
        with open("project.godot", 'r', encoding='utf-8') as f:
            content = f.read()
        
        # 检查是否包含旧路径
        for old_path in script_path_mapping.keys():
            if old_path in content:
                print(f"  - 发现旧路径: {old_path} 在project.godot文件中")
    except Exception as e:
        print(f"  - 处理project.godot文件时出错: {str(e)}")

print("检查完成！") 